﻿using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace BF3StatsNetApi.BLL
{
    /// <summary>
    /// This class is a placeholder for a list of <see cref="Player"/> objects.
    /// </summary>
    public class PlayerList
    {
        public string status { get; set; }
        private List<Player> _list;
        public object list { 
            get { return _list; } 
            set {
                _list = new List<Player>();
                foreach (KeyValuePair<string, JToken> lp in (JObject)value)
                {
                    Player _player = JsonConvert.DeserializeObject<Player>(lp.Value.ToString());
                    _list.Add(_player);
                }
            } 
        }
        public string error { get; set; }
        private List<Player> _failed;
        public object failed
        {
            get { return _failed; }
            set
            {
                _failed = new List<Player>();
                foreach (KeyValuePair<string, JToken> lp in (JObject)value)
                {
                    Player _player = JsonConvert.DeserializeObject<Player>(lp.Value.ToString());
                    _failed.Add(_player);
                }
            }
        }
    }
}
